/**
 * @fileOverview Page entry file
 * @author huangtonger@aliyun.com
 */

// const G6 = require('@antv/g6');
const G6 = require('../../../../g6/src');
const Page = require('./page');
const Util = require('./util/');
const baseShape = {
  getActivedStyle(/* item */) {},
  getSelectedStyle(/* item */) {},
  getStyle(/* item */) {},
  getPath(/* item */) {}
};
G6.registerNode('page-base', {
  ...baseShape
});
G6.registerEdge('page-base', {
  ...baseShape
});
G6.registerGroup('page-base', {
  ...baseShape
});
G6.registerGuide('page-base', {
  ...baseShape
});

function getExtendShape(extend, baseExtend, parentConstructorName) {
  let rst = [];
  if (Util.isString(extend)) {
    rst = [ baseExtend, extend ];
  } else if (Util.isArray(extend)) {
    extend.unshift(baseExtend);
    rst = extend;
  } else {
    rst = [ baseExtend ];
  }
  parentConstructorName && rst.unshift(parentConstructorName + '-base');
  return rst;
}

Page.setRegister = (Constructor, constructorName, parentConstructorName) => {
  Constructor.registerNode = (name, cfg, extend) => {
    G6.registerNode(name, cfg, getExtendShape(extend, constructorName + '-base', parentConstructorName));
  };
  Constructor.registerEdge = (name, cfg, extend) => {
    G6.registerEdge(name, cfg, getExtendShape(extend, constructorName + '-base', parentConstructorName));
  };
  Constructor.registerGroup = (name, cfg, extend) => {
    G6.registerGroup(name, cfg, getExtendShape(extend, constructorName + '-base', parentConstructorName));
  };
  Constructor.registerGuide = (name, cfg, extend) => {
    G6.registerGuide(name, cfg, getExtendShape(extend, constructorName + '-base', parentConstructorName));
  };
  Constructor.registerBehaviour = (name, behaviour, dependences) => {
    G6.registerBehaviour(name, graph => {
      const page = graph.get('page');
      page.set('_graph', graph);
      behaviour(page);
    }, dependences);
  };
};
Page.setRegister(Page, 'page');
require('./behaviour/');
module.exports = Page;
